<?php include('./templete/public/head.php') ?>

<body class="bgcolor">


<!--提议详情-->
<div class="golden-idea-detail tiyi-detail">
    <div class="ideal-detail1">
        <div class="detail-text">
            <p class="p1 pfbold"><?php echo $rows['title'] ?></p>
            <p class="p2"><?php echo $rows['problem_content'] ?></p>
            <p class="p3">
                <img src="<?php echo $rows['user_head'] ?>" class="head-img"/>
                <span><?php echo $rows['user_name'] ?><?php echo date('Y-m-d', strtotime($rows['add_time'])) ?></span>
            </p>
        </div>
    </div>
    <div class="ideal-detail2">
        <ul class="comm-table-view">
            <li class="table-view-cell">
                <a>
                    <span>提议分类</span>
                    <span><?php echo $rows['question_classfy'] ?></span>
                </a>
            </li>
            <?php if ($rows['_problem_file_url']) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>问题附件</span>
                        <span><a href="<?php echo $rows['_problem_file_url'] ?>" class="search-btn">(查看附件)</a></span>
                    </a>
                </li>
            <?php } ?>
            <li class="table-view-cell">
                <a>
                    <span>解决方案</span>
                    <span><?php echo $rows['solution_content'] ?></span>
                </a>
            </li>

            <?php if ($rows['_solution_file_url']) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>问题附件</span>
                        <span><a href="<?php echo $rows['_solution_file_url'] ?>" class="search-btn">(查看附件)</a></span>
                    </a>
                </li>
            <?php } ?>
            <li class="table-view-cell">
                <a>
                    <span>提议人</span>
                    <span><?php echo $rows['user_name'] ?></span>
                </a>
            </li>
            <li class="table-view-cell">
                <a>
                    <span>完成方式</span>
                    <span><?php if ($rows['complete_type'] == 1) echo '我提你改';
                        if ($rows['complete_type'] == 2) echo '自提自改';
                        if ($rows['complete_type'] == 3) echo '寻求合作'; ?></span>
                </a>
            </li>
            <?php if ($rows['hope_time']) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>希望完成时间</span>
                        <span><?php echo $rows['hope_time'] ?></span>
                    </a>
                </li>
            <?php } ?>

            <?php if (($rows['complete_type'] == 3) && ($rows['partners'])) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>合作人员</span>
                        <span><?php echo $rows['partners'] ?></span>
                    </a>
                </li>
            <?php } ?>
            <li class="table-view-cell">
                <a>
                    <span>是否形成知识产权</span>
                    <span><?php echo $rows['is_right'] ==1?"是":"否" ?></span>
                </a>
            </li>
            <?php if($rows['is_right'] ==1){?>
                <li class="table-view-cell">
                    <a>
                        <span>支持产权类型</span>
                        <span><?php echo $rows['right_type'] ==1?"专利":"商业秘密" ?></span>
                    </a>
                </li>
            <?php }?>
            <?php if ($rows['adopt_reason']) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>部门领导意见</span>
                        <span><?php echo $rows['adopt_reason'] ?></span>
                    </a>
                </li>
            <?php } ?>
            <?php if ($rows['class_reason']) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>分管领导意见</span>
                        <span><?php echo $rows['class_reason'] ?></span>
                    </a>
                </li>
            <?php } ?>
            <?php if ($rows['improve_content']) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>改善方案</span>
                        <span><?php echo $rows['improve_content'] ?></span>
                    </a>
                </li>
            <?php } ?>
            <?php if ((in_array($rows['status'], [4, 10, 12])) && ($is_publish_user || $is_my_leader_user)) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>补充提议</span>
                        <span style="display: flex;align-items: center;">
                            <button class="baoming-btn" id="supp_jjdz">补充提议</button>
                        </span>
                    </a>
                </li>
            <?php } ?>
            <li class="table-view-cell">
                <a>
                    <span>打分与评论</span>
                    <span style="display: flex;align-items: center;">
                        <button class="baoming-btn" id="view_comment">查看评论</button></span>
                </a>
            </li>
            <?php if ($is_publish_user || $is_leader_user) { ?>
                <li class="table-view-cell">
                    <a>
                        <span>任务列表</span>
                        <span style="display: flex;align-items: center;">
                        <button class="baoming-btn" id="view_task">查看任务列表</button></span>
                    </a>
                </li>
            <?php } ?>
        </ul>


        <?php if ((in_array($rows['status'], [4, 10, 12, 19])) && ($rows['complete_type'] != 3) && ($is_sure) && (!$has_sure)) { ?>
            <!--            自提自改-->
            <div class="detail2-btn comm-btn2 comm-btn"><span class="color1 accept_job">接受任务</span></div>

        <?php } ?>
        <?php if ((in_array($rows['status'], [4, 10, 12, 19])) && ($rows['complete_type'] == 3) && (!$is_sure || $is_pass)) { ?>
            <!--            自提自改-->
            <div class="detail2-btn comm-btn2 comm-btn"><span class="color1 accept_job">我来完成</span></div>
        <?php } ?>
        <?php if ((in_array($rows['status'], [4, 10, 12, 19])) && (!$user_finish) && ($is_task_user) && ($is_sure_content)) { ?>
            <div class="detail2-btn comm-btn2 comm-btn"><span class="color1 finish_job">完成任务</span></div>
        <?php } ?>
        <script>
            $(".accept_job").click(function () {
                layer.open({
                    type: 1,
                    title: '接受任务',
                    area: ['70%', '500px'], //宽高
                    content: '<ul class="comm-table-view">' +
                        '<li class="table-view-cell table-view-cell2">' +
                        '<a>' +
                        '<span>负责内容</span>' +
                        '<div class="fabu-text">' +
                        '<textarea id="task_content" style="    background-color: #EFEFEF;border: none;padding: 0.2rem;height: 2rem;margin-bottom: 0.25rem;"></textarea>' +
                        '</div>' +
                        '</a>' +
                        '</li>' +
                        '</ul>' +
                        '<div class="detail2-btn comm-btn2 comm-btn"><span class="color1" onclick="accept_job()">确认</span></div>',
                    shade: [0.5, '#000']
                })
            });
        </script>
        <div class="detail2-btn comm-btn comm-btn2">
            <?php if (in_array($rows['status'], [15]) && ($is_my_leader_user)) { ?>
                <!--                首次提交，部门领导审核?-->
                <span class="color1 adopt">进行评估(提议部门领导)</span>
            <?php } ?>
            <?php if (in_array($rows['status'], [15]) && ($is_publish_user)) { ?>
                <!--                首次提交，部门领导审核?-->
                <span class="color1 withdraw">撤回提议</span>
                <span class="color1 again">重新编辑</span>
            <?php } ?>
            <?php if (in_array($rows['status'], [1, 9]) && ($is_leader_user)) { ?>
                <!--                问题部门领导审核?-->
                <span class="color1 adopt">进行评估</span>
            <?php } ?>
            <?php if (in_array($rows['status'], [5]) && $is_class_user) { ?>
                <!--                复活提交。分管领导审核-->
                <span class="color1 adopt">分管领导进行评估</span>
            <?php } ?>
            <?php if (in_array($rows['status'], [17]) && $is_my_class_user) { ?>
                <!--                复活提交。我的分管领导审核-->
                <span class="color1 adopt">分管领导进行评估</span>
            <?php } ?>
            <?php if (in_array($rows['status'], [18]) && ($is_my_class_user)) { ?>
                <span class="color1 class_adopt">进行评估</span>
            <?php } ?>

            <?php if (in_array($rows['status'], [7]) && $is_manager) { ?>
                <!--                复活提交。总经理审核-->
                <span class="color1 adopt">总经理进行评估</span>
            <?php } ?>
            <?php if (in_array($rows['status'], [2, 11]) && ($is_class_user)) { ?>
                <span class="color1 class_adopt">进行评估</span>
            <?php } ?>
            <!--            超过48小时不允许在申请复活-->
            <?php if (in_array($rows['status'], [3, 6, 16]) && ($is_publish_user) && ((time() - strtotime($rows['adopt_time']) < 172800))) { ?>
                <span class="color1 revive">申请复活</span>
            <?php } ?>
            <?php if (in_array($rows['status'], [13, 14]) && ($is_leader_user||$is_class_user) && !$is_score) { ?>
                <!--                验收人打分-->
                <span class="color1 acceptor">打分验收</span>
            <?php } ?>
            <?php if ($is_publish_user && $rows['status'] == 19) { ?>
                <span class="color1 finish_confirm">完成确认</span>
            <?php } ?>
        </div>
    </div>
    <!--时间进展-->
    <div class="ideal-detail3">
        <p class="title">时间进度</p>
        <ul class="detail3-list">
            <?php
            $b = json_decode($rows['log'], true);
            $last_names = array_column($b, 'times');
            array_multisort($last_names, SORT_DESC, $b);
            ?>
            <li class="list-item">
                <a>
                    <div class="item-text">
                        <p class="p1 clearfix">
                            <span class="fl"><?php if ($next_status == 1) {
                                    echo '结束';
                                } elseif ($next_status == 2) {
                                    echo '关闭';
                                } else {
                                    echo '下一阶段';
                                } ?></span>
                        </p>
                        <?php if (($next_status != 1) && ($next_status != 2)) { ?>
                            <p class="p2"><?php echo $next_status ?></p>
                        <?php } ?>
                    </div>
                </a>
            </li>
            <?php foreach ($b as $v) { ?>
                <li class="list-item">
                    <a onclick="showmessage(this)">
                        <p style="display: none" class="message_content"><?php echo $v['content']?></p>
                        <p style="display: none" class="message_file_url"><?php echo $v['file_url']?></p>
                        <img src="<?php echo $v['user_head'] ?>" class="head-img"/>
                        <div class="item-text">
                            <p class="p1 clearfix">
                                <span class="fl"><?php echo $v['user_name'] ?></span>
                                <span class="fr"><?php echo date('m-d H:i', $v['times']) ?></span>
                            </p>
                            <p class="p2"><i class="iconfont icon-wancheng"></i><?php echo $v['message'] ?></p>
                        </div>
                    </a>
                </li>
            <?php } ?>
        </ul>
    </div>
</div>
</body>
</html>
<script>
    $('.adopt').click(function () {
        location.href = '/index/jdz/adopt/id/' + '<?php echo $rows['id']?>'
    });
    //撤回
    $('.withdraw').click(function () {
        layer.confirm('确认撤回次提议吗？', {
            btn: ['确认', '取消']
        }, function () {
            $.ajax({
                url: '<?php echo url("withdraw")?>',
                data: {
                    id:<?php echo $rows['id']?>,
                },
                success: function (data) {
                    layer.msg(data.msg);
                    //  location.reload();
                }
            })
        }, function () {
            layer.msg('操作已取消');
        })
    });
    //重新编辑
    $('.again').click(function () {
        location.href = '/index/jdz/again/id/' + '<?php echo $rows['id']?>'
    });
    $('.class_adopt').click(function () {
        location.href = '/index/jdz/class_adopt/id/' + '<?php echo $rows['id']?>'
    });
    $('.revive').click(function () {
        location.href = '/index/jdz/revive/id/' + '<?php echo $rows['id']?>'
    });
    $('.acceptor').click(function () {
        location.href = '/index/jdz/acceptor/id/' + '<?php echo $rows['id']?>'
    });
    $("#supp_jjdz").click(function () {
        location.href = "<?php echo url('jdz/supp_jdz', ['id' => $rows['id']]) ?>";
    });
    $("#view_comment").click(function () {
        location.href = "<?php echo url('jdz/comment', ['id' => $rows['id']]) ?>";
    });
    $("#view_task").click(function () {
        location.href = "<?php echo url('jdz/task_list', ['id' => $rows['id']]) ?>";
    });
    $(".finish_job").click(function () {
        location.href = "<?php echo url('jdz/finish_jdz', ['id' => $rows['id']]) ?>";
    });
    $(".finish_confirm").click(function () {
        layer.confirm('请确认提议已经完成', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                url: "<?php echo url('finish_confirm')?>",
                data: {
                    id:<?php echo $rows['id']?>
                },
                success: function (data) {
                    layer.msg(data.msg);
                    setTimeout(function () {
                        location.href = "<?php echo url('detail', ['id' => $rows['id']])?>"
                    }, 1000)
                }
            })
        }, function () {
            layer.msg('取消成功');
        });

    });

    function accept_job() {
        if (!$('#task_content').val()) {
            layer.msg('接受任务，请输入负责内容');
            return false;
        }
        layer.msg('提交中',{time:60000,icon: 16,shade: 0.3});
        $.ajax({
            url: '<?php echo url('confirm_jdz')?>',
            type: 'post',
            data: {
                confirm_content: $('#task_content').val(),
                jdz_id:<?php echo $rows['id']?>,
            },
            success: function (data) {
                layer.msg(data.msg);
                setTimeout(function () {
                    layer.closeAll();
                    location.reload();
                }, 1000);
            }

        })
    }

    $('.confirm').click(function () {
        if (!$('#task_content').val()) {
            layer.msg('接受任务，请输入负责内容');
            return false;
        }
        layer.msg('提交中',{time:60000,icon: 16,shade: 0.3});
        $.ajax({
            url: '<?php echo url('confirm_jdz')?>',
            type: 'post',
            data: {
                confirm_content: $('#task_content').val(),
                jdz_id:<?php echo $rows['id']?>,
            },
            success: function (data) {
                layer.msg(data.msg);
                setTimeout(function () {
                    layer.closeAll();
                    location.reload();
                }, 1000);
            }

        })
    });
    $('.finish').click(function () {
        if (!$('#finish_content').val()) {
            layer.msg('请输入完成内容');
            return false;
        }
        layer.msg('提交中',{time:60000,icon: 16,shade: 0.3});
        $.ajax({
            url: '<?php echo url('finish_jdz')?>',
            type: 'post',
            data: {
                finish_content: $('#finish_content').val(),
                jdz_id:<?php echo $rows['id']?>,
            },
            success: function (data) {
                layer.msg(data.msg);
                setTimeout(function () {
                    layer.closeAll();
                    location.reload();
                }, 1000);
            }

        })
    });

    function showmessage(obj) {
        var content =$(obj).children('.message_content').text();
        var file_url = $(obj).children('.message_file_url').text();
        if (file_url) {
            var file_url = eval('(' + file_url + ')');
        }
        if (!content) {
            layer.msg('暂无内容')
        } else {
            var html = '<div class="text-down">' +
                '<div class="content">' + content + '</div>';
            console.log(file_url);
            if (file_url) {
                $.each(file_url,function (k,v) {
                    html += '<img src="' + v + '" alt="" width="100%" height="auto" style="align:center;">' +
                        '<a class="down-btn" href="' + v + '">下载</a>'
                })

            }
            html += '</div>';
            console.log(html);
            layer.open({
                type: 1,
                title: '进度详情',
                area: ['70%', '90%'], //宽高
                content: html,
                shade: [0.5, '#000']
            });
        }
    }


</script>